using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace SCSEngine.Utils.Entities.Component.Accelerometer
{
    public class AccelerometComponent : IGameComponent, IAccelerometComponent
    {
        private Vector3 accel;
        private Vector2 accel2D;

        public Vector2 Value2D
        {
            get { return accel2D; }
            set { accel2D = value; accel = new Vector3(value, 0f); }
        }

        public Vector3 Value
        {
            get { return accel; }
            set { accel = value; accel2D.X = value.X; accel.Y = value.Y; }
        }

        public float X
        {
            get { return accel.X; }
            set { accel.X = value; accel2D.X = value; }
        }

        public float Y
        {
            get { return accel.Y; }
            set { accel.Y = value; accel2D.Y = value; }
        }

        public float Z
        {
            get { return accel.Z; }
            set { accel.Z = value; }
        }

        public float Phi
        {
            get { return (float)Math.Atan2(this.accel.Y, this.accel.X); }
        }

        public float Theta
        {
            get { return (float)Math.Acos(accel.Z / this.Length); }
        }

        public float Length
        {
            get { return this.accel.Length(); }
            set { Vector3 dir = this.accel; dir.Normalize(); this.accel = value * dir; }
        }

        public void Initialize()
        {
        }
    }
}
